class Enigma < ActiveRecord::Base
  
  validates_uniqueness_of :enigma
  
  def self.random(user)
    #try 3 times  
    count = 0
    while count < 3 do
      enigma = Enigma.find :first, :offset => ( Enigma.count * rand ).to_i
      user_match = user.user_matches.find_by_enigma_id(enigma.id)
      break if !user_match 
      count+=1
    end
    enigma
    
  end
  
end
